/*
我是公共组件搜索卡片
 */

<template>
  <div class="FormCard">
    <el-card>
      <el-form ref="form" :model="formData">
        <el-row type="flex" class="row-bg" justify="space-between">
          <el-col :span="18">
            <el-row>
              <el-col v-for="(value,key) in commerceEnum[formCardName]" :key="value" :span="8">
                <el-form-item :label="value">
                  <el-input v-model="formData[key]" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="6">
            <el-row type="flex" justify="space-around" align="middle">
              <el-form-item class="btn">
                <el-button class="search" @click="search">搜索</el-button>
                <el-button class="reset" @click="reset">重置</el-button>
              </el-form-item>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import commerceEnum from '@/constan/commerce'
import { mapState } from 'vuex'

export default {
  name: 'FormCard',
  props: {
    enumName: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      formData: {},
      commerceEnum,
      formCardName: this.enumName + 'Form'
    }
  },
  computed: {
    ...mapState('formCard', ['current', 'size'])
  },
  created() {
    for (const key in commerceEnum[this.enumName + 'Form']) {
      this.$set(this.formData, [key], '')
    }
  },
  methods: {
    async reset() {
      // this.formData = await this.$options.data().formData
      for (const key in commerceEnum[this.enumName + 'Form']) {
        this.$set(this.formData, [key], '')
      }
      await this.$refs.form.resetFields()
      this.search(true)
    },
    search(message) {
      this.$emit('render', { ...this.formData, current: 1 })
      this.$message.success((message === true ? '重置' : '操作') + '成功')
    }
  }

}
</script>

<style lang="scss">
.el-input__inner {
  background-color: #f8f5f5;
  border-color: transparent;
}
</style>

<style lang="scss" scoped>
.FormCard {
  width: 95%;
  margin: 20px auto;

  .el-card {
    border-radius: 10px;

    .el-form-item {
      margin: 0 20px;

    }
   .el-row.is-justify-space-around.is-align-middle.el-row--flex{
    //  height: 100%;
    margin-top: 40px;
    }

    .el-button {
      border-radius: 5px;
  border-color: transparent;
// :hover{
//       background-color: rgb(255, 179, 0);
//       color: #fff;
// }
    }

.el-button:focus, .el-button:hover{
      background-color: rgb(255, 179, 0);
      color: #fff;
}
    .search{
      background-color: rgb(254, 233, 184);
    }

        .reset{
  background-color: #f8f5f5;

    }
  }

}
</style>
